package com.comp490.bullet;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import com.comp490.shooter.GameView;
import com.comp490.sprite.BitmapResource;
import com.comp490.sprite.Ship;

public class YellowPlayerBullet extends Bullet
{
    private Bitmap bitmap;

    public YellowPlayerBullet(float x, float y, int damage, boolean active)
    {
        super(x, y, damage, active);
        bitmap = BitmapResource.PLAYER_BULLET;

        radius = bitmap.getHeight() < bitmap.getWidth() ? bitmap
                .getHeight() / 2 : bitmap.getWidth() / 2;
    }

    public float getCenterBitmapX()
    {
        return BitmapResource.PLAYER_BULLET_CENTER_WIDTH + x;
    }

    public float getCenterBitmapY()
    {
        return BitmapResource.PLAYER_BULLET_CENTER_HEIGHT + y;
    }

    public float collisionRadius()
    {
        return radius;
    }

    @Override
    public boolean boundsCheck(GameView g)
    {
        return x > 0 && x < g.getWidth() && y > -15 && y < g.getHeight();
    }

    @Override
    public boolean collisionCheck(Ship object)
    {
        float dx = x - object.getCenterBitmapX();
        float dy = y - object.getCenterBitmapY();
        return android.util.FloatMath.sqrt(dx * dx + dy * dy) < radius
                + object.collisionRadius();
    }

    @Override
    public void draw(Canvas c)
    {
        c.drawBitmap(bitmap, x,
                y - BitmapResource.PLAYER_BULLET_CENTER_HEIGHT, null);
    }
}
